home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / d.t.p / utils / propage / donsgenies / donsgenies.lha / Don'sGenies / AdvantageTableImport.pprx next >
Text File  |  1993-08-12  |  8KB  |  236 lines

  1. /*
  2. AdvantageTableImport  
  3.  
  4. This Genie will import a table of data from Advantage. You must have Advantage running first and a box on the page for which the data is destined.
  5. Written by Don Cox, Aug 93. Based on "ProCalc Import" genie and Advantage "Table" script. 
  6. */
  7. numeric digits 8
  8. cr  = '0a'x
  9. options results
  10.  
  11. trace n
  12. address command
  13. call SafeEndEdit.rexx()
  14. oldunits = ppm_GetUnits()
  15. call ppm_SetUnits(1)
  16. call ppm_AutoUpdate(0)
  17.  
  18. signal on halt
  19. signal on break_c
  20. signal on break_e
  21. signal on break_d
  22.  
  23. if ~show(p, "Advantage") then exit_msg("Please start Advantage and select a range before running this Genie.")
  24.  
  25. box = ppm_ClickOnBox("Click on box in which to import table..")
  26. if box = 0 then exit_msg()
  27.  
  28. /*  extract box attributes  */
  29. boxsize = ppm_GetBoxSize(box)
  30. boxposition = ppm_GetBoxPosition(box)
  31.  
  32. if ppm_Inform(2, "Delete box?",) = 1 then call ppm_DeleteBox(box)
  33.  
  34. /* tell user to start up Advantage    */
  35. call ppm_Inform(1, "Select Range in Advantage",)
  36. call ppm_ShowStatus("Extracting range from Advantage")
  37.  
  38.  
  39. address 'Advantage'             /* Send commands to Advantage. */
  40. options results                 /* Enable return of string results. */
  41.  
  42. 'Current'                       /* Determine current selected range. */
  43. range = result
  44.  
  45. colon_posn = pos(":",range)     /* Look for colon delimiter in range. */
  46.  
  47. if colon_posn = 0 then          /* If no colon, this is not a range. */
  48.    do                           /*  Set the start and end cells to   */
  49.       start_cell = range        /*   the selected cell.              */
  50.       end_cell = range
  51.    end
  52. else                            /* Otherwise, it is a range. */
  53.    /* Extract the start/end cells from the specified range. */
  54.    do
  55.       start_cell = left(range,colon_posn - 1)
  56.       end_cell   = substr(range,colon_posn + 1)
  57.    end
  58.    
  59. start_column = GetColumn(start_cell)    /* Determine range of columns */
  60. end_column   = GetColumn(end_cell)      /*  to be filled.             */
  61.  
  62. start_row = GetRow(start_cell)          /* Determine range of rows */
  63. end_row   = GetRow(end_cell)            /*  to be filled.          */
  64.  
  65. matrix. = ""
  66.  
  67. do rownum = start_row to end_row
  68.    
  69.    column = start_column                /* Reset column pointer.  */
  70.    
  71.    /* Read all columns in the current row. */
  72.    do until c2d(column) > c2d(end_column)
  73.       /* Build complete cell name from row and column. */
  74.       next_cell = column || rownum
  75.       /* Select the cell to be modified. */
  76.       'SelectCell'                   
  77.       value(next_cell)
  78.       'GetValue'
  79.       /* Put results into a matrix */
  80.       matrix.rownum.column = result
  81.       /* Advance to the next column and table entry. */
  82.       column = NextColumn(column)
  83.       
  84.    end
  85.    
  86. end rownum
  87.       
  88.  
  89. EndCol = c2d(end_column)
  90. StartCol=c2d(start_column)
  91.  
  92. /*  calculate the dimensions of the new boxes   */
  93. boxwidth    = word(boxsize, 1 ) / (EndCol - StartCol + 1 )
  94. boxheight   = word(boxsize, 2 ) / (end_row - start_row + 1 )
  95. boxleft     = word(boxposition, 1 )
  96. boxtop      = word(boxposition, 2 )
  97. boxright    = word(boxsize, 1) + boxleft
  98. boxbottom   = word(boxsize, 2) + boxtop
  99. boxmargin   = boxheight/20
  100.  
  101.  
  102. call ppm_AutoUpdate(0)
  103.  
  104. bleft   = boxleft
  105. btop    = boxtop
  106.  
  107. selection   = "Right Justify Numbers"cr"Make Grid Lines"
  108. selection   = upper(ppm_SelectFromList("Select Options", 30, 5, 1, selection))
  109. if pos(GRID, selection) ~= 0 then grid = 1
  110. else grid       = 0
  111. if pos(RIGHT, selection) ~= 0 then right = 1
  112. else right  = 0
  113.  
  114.  
  115. call ppm_SetSize(boxheight*52) /* Type size a bit less than box height, in points */ 
  116.  
  117. do rownum = start_row to end_row
  118.  
  119.     do column = StartCol to EndCol
  120.  
  121.         col = d2c(column)
  122.         box = ppm_CreateBox(bleft, btop, boxwidth, boxheight, 0,        "CELL "col"-"rownum)
  123.         bleft   = bleft + boxwidth
  124.         call ppm_SetBoxMargins(box, boxmargin*2, boxmargin, boxmargin*2, boxmargin)
  125.  
  126.         if grid then
  127.         do
  128.             call ppm_SetBoxFrame(box, 1)
  129.             call ppm_SetBoxFrameData(box, "black", "black", .5, 1, 0)
  130.         end
  131.  
  132.                 if matrix.rownum.col = "" then matrix.rownum.col = " "
  133.  
  134.         if right & datatype(matrix.rownum.col) = 'NUM' then
  135.             call ppm_TextIntoBox(box, "\jr"matrix.rownum.col)
  136.         else
  137.             call ppm_TextIntoBox(box, "\jl"matrix.rownum.col)
  138.     end
  139.  
  140.     bleft   = boxleft
  141.     btop    = btop  + boxheight
  142.  
  143. end
  144.  
  145.  
  146. exit_msg("Done","Resume")
  147. break_d:
  148. break_e:
  149. break_c:
  150. halt:
  151.     call exit_msg("User aborted Genie")
  152.  
  153. exit_msg: procedure expose oldunits
  154. do
  155.     parse arg message
  156.  
  157.     call ppm_ClearStatus()
  158.     if message ~= '' then call ppm_Inform(1, message,)
  159.     call ppm_SetUnits(oldunits)
  160.     call ppm_AutoUpdate(1)
  161.     exit
  162. end
  163.  
  164.  
  165. /* ----------------------------------------------------------------- */
  166. /*            Internal Functions (subroutines)                       */
  167. /* ----------------------------------------------------------------- */
  168.  
  169. /* == GetRow: Extract the row number from a cell name. == */
  170.  
  171. GetRow: procedure
  172.    arg CellName      /* Function expects to be passed a cell name. */
  173.  
  174.    /* Find the first numeric digit in the cell name. */
  175.    start_number = verify(CellName,"0123456789","Match")
  176.    
  177.    /* Extract all characters starting at the first digit and continuing */
  178.    /* to the end of the cell name.                                      */
  179.    rownum = substr(CellName,start_number)
  180.  
  181. return rownum
  182.  
  183. /* == GetColumn: Extract the column label from a cell name. == */
  184.  
  185. GetColumn: procedure
  186.    arg CellName      /* Function expects to be passed a cell name. */
  187.  
  188.    /* Find the first numeric digit in the cell name. */
  189.    start_number = verify(CellName,"0123456789","Match")
  190.    
  191.    /* Extract all characters in the cell name up to the first numeric */
  192.    /* character (start of row number).                                */
  193.    column = left(CellName,start_number-1)
  194.  
  195. return column
  196.  
  197. /* == NextColumn: Given the current column label, determine the label == */
  198. /* ==              for the next sequential column. NOTE: This is a    == */
  199. /* ==              recursive function.                                == */
  200.  
  201. NextColumn: procedure
  202.    arg ThisColumn    /* Function expects to be passed a column label. */
  203.  
  204.    /* If the column label is empty (null string), then we must be */
  205.    /* starting a new group of column labels (for example, going   */
  206.    /* from column ZZ to column AAA. Return an "A".                */
  207.    if length(ThisColumn) = 0 then
  208.       new_column = "A"
  209.    
  210.    /* Otherwise, we must advance the last character in the column */
  211.    /* name to the next sequential alphabetic character.           */
  212.    else
  213.       do
  214.          col_number = ,                 /* Convert last character */
  215.             c2d( right(ThisColumn,1) )  /*  to decimal value.     */
  216.    
  217.          col_number = col_number + 1    /* Increment to next character. */
  218.          new_char = d2c(col_number)     /* Convert back to a character. */
  219.    
  220.          /* If we've gone past 'Z', find the next column for the column */
  221.          /* label minus the last character and then append an "A" to    */
  222.          /* this label (start of a new label set).                      */
  223.          if new_char > "Z" then
  224.             do
  225.                temp_column = left( ThisColumn, length(ThisColumn)-1 )
  226.                new_column = NextColumn(temp_column) || "A"
  227.             end
  228.          
  229.          /* Otherwise, replace the last character of the column label */
  230.          /* with the next sequential character.                       */
  231.          else
  232.             new_column = overlay(new_char,ThisColumn,length(ThisColumn))
  233.       end
  234.  
  235. return new_column
  236.